﻿using Sidvall.Security;

namespace Sidvall.Serialization
{
	public static class UserInfoExtension
	{
		#region GetName

		public static string GetName(this UserInfo value)
		{
			if (value == null)
				return null;
			return value.Items.ValueToString(ClaimTypes.Name, null);
		}

		#endregion
		#region GetEmail

		public static string GetEmail(this UserInfo value)
		{
			if (value == null)
				return null;
			return value.Items.ValueToString(ClaimTypes.Email, null);
		}

		#endregion
		#region GetEmailVerified

		public static bool GetEmailVerified(this UserInfo value)
		{
			if (value == null)
				return false;
			return value.Items.ValueToBoolean(ClaimTypes.EmailVerified, false);
		}

		#endregion
		#region GetPhoneNumber

		public static string GetPhoneNumber(this UserInfo value)
		{
			if (value == null)
				return null;
			return value.Items.ValueToString(ClaimTypes.PhoneNumber, null);
		}

		#endregion
		#region GetPhoneNumberVerified

		public static bool GetPhoneNumberVerified(this UserInfo value)
		{
			if (value == null)
				return false;
			return value.Items.ValueToBoolean(ClaimTypes.PhoneNumberVerified, false);
		}

		#endregion

		#region SetName

		public static void SetName(this UserInfo item, string value)
		{
			if (item == null)
				return;
			item.Items.Remove(ClaimTypes.Name);
			item.Items.Add(ClaimTypes.Name, value);
		}

		#endregion
		#region SetEmail

		public static void SetEmail(this UserInfo item, string value)
		{
			if (item == null)
				return;
			item.Items.Remove(ClaimTypes.Email);
			item.Items.Add(ClaimTypes.Email, value);
		}

		#endregion
		#region SetPhoneNumber

		public static void SetPhoneNumber(this UserInfo item, string value)
		{
			if (item == null)
				return;
			item.Items.Remove(ClaimTypes.PhoneNumber);
			item.Items.Add(ClaimTypes.PhoneNumber, value);
		}

		#endregion
	}
}
